class Project < ActiveRecord::Base
  has_many :exemplars do
    def current
      find :first, :order => 'id desc'
    end
  end
  
  has_many :outputs
  has_many :computations
  
  before_create do |p|
    exem = p.exemplars.first
    if exem
      p.name ||= exem.filename
    end
  end
  
  after_create do |p|
    p.update_attribute(:visible_columns, p.current_exemplar.grid_data.columns.join(","))
  end
  
  def current_exemplar
    @current_exemplar ||= exemplars.current
  end
  
  def hidden_columns_ary
    (self.hidden_columns || '').split(",")
  end
  
  def visible_columns_ary
    (self.visible_columns || '').split(",")
  end
end
